package com.xyb.service;

import com.xyb.dao.BizChartDao;
import com.xyb.entity.BizChart;
import com.xyb.utils.IdUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ChartService {
    @Resource
    private IdUtils idUtils;
    @Resource
    private BizChartDao bizChartDao;

    public List<BizChart> selectBizChart(int status) {
        List<BizChart> chartList = bizChartDao.selectBizChartByStatus(status);
        return chartList;
    }

    public String insertBizChart(BizChart bizChart) {
        long nextId = idUtils.nextId();
        {
            bizChart.setChartId(nextId);
            bizChart.setStatus(1);
        }
        bizChartDao.insertBizChart(bizChart);
        return "success";
    }

    public String updateBizChartByChartId(BizChart bizChart) {
        bizChartDao.updateBizChartByChartId(bizChart);
        return "success";
    }

    public String deleteBizChartByChartId(Long chartId) {
        bizChartDao.deleteBizChartByChartId(chartId);
        return "success";
    }

    public String updateBizChartShowOrder(Long[] chartIds) {
        List<BizChart> list = new ArrayList<>();
        for (int i = 0,length = chartIds.length; i < length; i++) {
            BizChart bizChart = new BizChart();
            bizChart.setChartId(chartIds[i]);
            bizChart.setShowOrder(i);
            list.add(bizChart);
        }
        bizChartDao.updateBizChartByBizChartList(list);
        return "success";
    }
}
